#!/bin/bash

# turn off eth and wifi

#ethd=$( networksetup -listallhardwareports | awk '$3=="Ethernet" {getline; print $2}')
# if ethd was Enabled before sleep - renable it ie turn back on 
if [[ -f /var/tmp/eth.status.txt ]]
then
status=$(cat /var/tmp/eth.status.txt)
	if [[ $status == "Enabled" ]]
	then
	networksetup -setnetworkserviceenabled Ethernet on
	fi
rm /var/tmp/eth.status.txt
fi

# if ethd was Enabled before sleep - renable it ie turn back on 
if [[ -f /var/tmp/wifi.status.txt ]]
then
status=$(cat /var/tmp/wifi.status.txt)
	if [[ ${status##*: } == "On" ]]
	then
	wifi=$( networksetup -listallhardwareports | awk '$3=="Wi-Fi"    {getline; print $2}')
	(sleep 1; networksetup -setairportpower $wifi on ) &
	fi
rm /var/tmp/wifi.status.txt
fi

#fix no camera after sleep
sudo killall VDCAssistant

exit 
